//void, Obj This

Building this;

Sleep(rand(1000) + 500);

this = This.AsBuilding();

if (!.IsValid) return;
//pr("auto pop dziala");
while(.IsValid){

	if(EnvReadString(.settlement, "auto_add_pop") == "yes"){
		int max_pop;
			
		max_pop = .settlement.max_population - 10;
		if(.settlement.population <= max_pop){
			if(.settlement.food >= 1000){
				point ptDummy; Obj objDummy;
				str cmd;
						
				cmd = GetRaceStrPref(.settlement.GetCentralBuilding.race) + "AddPop"; 
				if(EnvReadString(.settlement, "auto_add_pop_end") != "no"){
					.ExecCmd(cmd, ptDummy, objDummy, false);
					Sleep(6000);
				} else {
					.ExecCmd(cmd, ptDummy, objDummy, false);
					Sleep(60000);
				}
				EnvWriteString(.settlement, "auto_add_pop_end", "no");
			}
		}
	}
    Sleep(10000+rand(100));
}